package com.server.file.controller;

import com.server.model.all.enums.BucketNameEnum;
import com.server.model.all.enums.BusinessNameEnum;
import com.server.common.code.utils.AjaxResult;
import com.server.commons.file.interfaces.FileFactoryInterface;
import com.server.commons.file.model.input.UploadFileInput;
import com.server.common.security.code.anntation.Log;
import com.server.file.service.FileUpLoadService;
import com.server.file.utils.UploadFileInputBuilder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping(path = "/fileUpLoad")
public class FileController {

    @Resource
    private FileFactoryInterface fileFactoryInterface;

    @Resource
    private FileUpLoadService fileUpLoadService;


    /**
     * 上传图片
     * @author LXC
     * @date 2022/5/6 9:26
     */
    @Log
    @PostMapping("/upLoadMainAndThumbnailImage")
    public AjaxResult upLoadMainAndThumbnailImage(@RequestParam("file") MultipartFile file) {
        UploadFileInput uploadFileInput = UploadFileInputBuilder.builder()
                .multipartFile(file)
                .businessName(BusinessNameEnum.IMAGE)
                .bucketName(BucketNameEnum.MAIN_IMAGE)
                .build();
        return AjaxResult.successData(fileUpLoadService.upLoadMainAndThumbnailImage(uploadFileInput));
    }

    /**
     * 上传文件
     * @author LXC
     * @date 2023/3/1 20:03
     */
    @Log
    @PostMapping("/uploadFile")
    public AjaxResult uploadFile(@RequestParam("file") MultipartFile file){
        UploadFileInput uploadFileInput = UploadFileInputBuilder.builder()
                .multipartFile(file)
                .businessName(BusinessNameEnum.IMAGE)
                .bucketName(BucketNameEnum.MAIN_IMAGE)
                .build();
        return AjaxResult.successData(fileUpLoadService.uploadFile(uploadFileInput));
    }

}
